package com.piggy.im.server.mq;

import com.piggy.im.domain.bo.SysPublishMsgBo;
import com.piggy.im.mq.model.StationMsgMQ;
import com.piggy.im.server.service.ISysStationMessagePublishService;
import com.piggy.mq.vender.IMQMsgReceiver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class StationMQReceiver implements IMQMsgReceiver {

    @Resource
    private ISysStationMessagePublishService stationService;

    @Override
    //@Async(MqThreadExecutor.EXECUTOR_NOTIFY)
    @RabbitListener(queues = StationMsgMQ.MQ_NAME)
    public void receiveMsg(String msg) {
        SysPublishMsgBo bo = StationMsgMQ.parse(msg);
        try {
            stationService.publishMsg(bo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

}
